package GUI;


import java.awt.Color;
import javax.swing.JOptionPane;
import Planejamento.Caminho.Caminho;
import Mapeamento.QuadTree.Arvore;
import java.awt.event.MouseEvent;



public class Frame extends javax.swing.JFrame {
    
    // Fator de escala entre o labirinto real e o simulado
    private int fator_de_escala = 3;

    // Interface JPanel
    private javax.swing.JPanel campo;
    private javax.swing.JPanel controlePanel;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel obstaculosPanel;
    private javax.swing.JPanel Exibir;

    // Interface JButton
    private javax.swing.JButton expandir;
    private javax.swing.JButton origemdestino;
    private javax.swing.JButton gerarCaminho;
    private javax.swing.JButton grafo;
    private javax.swing.JButton reiniciar;
    private javax.swing.JButton tamanho1;
    private javax.swing.JButton tamanho2;
    private javax.swing.JButton tamanho3;

    // Check-Box
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;

    // Interface JToggleButton - Permite dois estados: Inserir e Feito
    private javax.swing.JToggleButton inserir;

    // Classe que extends Panel
    private Controle labirintoPanel;

    // Variaveis de controle
    private boolean inserirPontos = false;
    private int n_pontos = 0;
    private boolean action = false;
    private int controle = 0;
    private int controle2 = 0;
    private boolean expandirTemp = false;
    private boolean odTemp = false;
    private boolean caminhoTemp = false;

    private Color azul = new Color(51, 153, 255);

    public Frame() {
        initComponents();

    }

    @SuppressWarnings("unchecked")
   
    private void initComponents() {

        labirintoPanel = new Controle();

        controlePanel = new javax.swing.JPanel();
        obstaculosPanel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        Exibir = new javax.swing.JPanel();

        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        
        tamanho1 = new javax.swing.JButton();
        tamanho2 = new javax.swing.JButton();
        tamanho3 = new javax.swing.JButton();
        reiniciar = new javax.swing.JButton();
        origemdestino = new javax.swing.JButton();
        expandir = new javax.swing.JButton();
        gerarCaminho = new javax.swing.JButton();
        grafo = new javax.swing.JButton();

        inserir = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema Robotico Multiagente para Transporte Colaborativo");

        // Configurando o Panel labirintoPanel
        labirintoPanel.setBackground(new java.awt.Color(0, 0, 100));
        labirintoPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        labirintoPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                campoMouseReleased(evt);
            }
        });

        // Configurando o controlePanel
        controlePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle"));
        controlePanel.setPreferredSize(new java.awt.Dimension(300, fator_de_escala*220));

        // Estruturando o controlePanel
        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(controlePanel);
        controlePanel.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(Exibir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(obstaculosPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup().addGap(15, 15, 15)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(reiniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(grafo, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(gerarCaminho, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(origemdestino, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(expandir, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap())
        );

        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(obstaculosPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                .addComponent(Exibir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                .addComponent(expandir, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(origemdestino, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(gerarCaminho, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(grafo, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(reiniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
       .addContainerGap()));

        // Configurando o obstaculosPanel
        obstaculosPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Obstáculos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14)));

        // Estruturando o obstaculosPanel
        javax.swing.GroupLayout obstaculosLayout = new javax.swing.GroupLayout(obstaculosPanel);
        obstaculosPanel.setLayout(obstaculosLayout);
        obstaculosLayout.setHorizontalGroup(
                obstaculosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(obstaculosLayout.createSequentialGroup().addGroup(obstaculosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(obstaculosLayout.createSequentialGroup().addGap(45, 45, 45).addComponent(tamanho1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).addComponent(tamanho2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).addComponent(tamanho3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(obstaculosLayout.createSequentialGroup().addContainerGap().addComponent(inserir, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE))).addContainerGap()));
        obstaculosLayout.setVerticalGroup(
                obstaculosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(obstaculosLayout.createSequentialGroup().addContainerGap().addGroup(obstaculosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(tamanho1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(tamanho2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(tamanho3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(inserir, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE).addGap(11, 11, 11)));


        // Configurando o JToggleButton inserir
        inserir.setFont(new java.awt.Font("Tahoma", 1, 14));
        inserir.setText("Inserir");
        inserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionInserirFeito(evt);
            }
        });

        // Configurando os tres botoes para seleçao do tamanho dos obstaculos
        tamanho1.setBackground(java.awt.Color.lightGray);
        tamanho1.setPreferredSize(new java.awt.Dimension(20, 20));
        tamanho1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tamanho1ActionPerformed(evt);
            }
        });

        tamanho2.setBackground(java.awt.Color.lightGray);
        tamanho2.setPreferredSize(new java.awt.Dimension(40, 40));
        tamanho2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tamanho2ActionPerformed(evt);
            }
        });

        tamanho3.setBackground(java.awt.Color.lightGray);
        tamanho3.setPreferredSize(new java.awt.Dimension(80, 80));
        tamanho3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tamanho3ActionPerformed(evt);
            }
        });


        // Botao para reiniciar
        reiniciar.setFont(new java.awt.Font("Tahoma", 1, 14));
        reiniciar.setText("Reiniciar");
        reiniciar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        // Botao para definir origem e destino
        origemdestino.setFont(new java.awt.Font("Tahoma", 1, 14));
        origemdestino.setText("Origem e Destino");
        origemdestino.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gerarMouseClicked(evt);
            }
        });
        
        // Botao para expandir os obstaculos
        expandir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        expandir.setText("Expandir");
        expandir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                expandirMouseClicked(evt);
            }
        });
        
        // Botao para gerar caminho
        gerarCaminho.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        gerarCaminho.setText("Gerar Caminho");
        gerarCaminho.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gerarCaminhoMouseClicked(evt);
            }
        });

        // Botao para inserir o grafo desenho
        grafo.setFont(new java.awt.Font("Tahoma", 1, 14));
        grafo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        grafo.setText("---");
        grafo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                percorrerMouseClicked(evt);
            }
        });

        // Configurando o ExibirPanel

        Exibir.setBorder(javax.swing.BorderFactory.createTitledBorder("Exibir"));

        jCheckBox1.setText("Grafo");

        jCheckBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox1MouseClicked(evt);
            }
        });

        jCheckBox2.setText("Caminho");

        jCheckBox2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox2MouseClicked(evt);
            }
        });

        jCheckBox3.setText("Obstaculos");

        jCheckBox3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox3MouseClicked(evt);
            }
        });

        jCheckBox4.setText("Mapeamento - Quad-Tree");

        jCheckBox4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox4MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout ExibirLayout = new javax.swing.GroupLayout(Exibir);
        Exibir.setLayout(ExibirLayout);
        ExibirLayout.setHorizontalGroup(
            ExibirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ExibirLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ExibirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox4))
                .addContainerGap(94, Short.MAX_VALUE))
        );
        ExibirLayout.setVerticalGroup(
            ExibirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ExibirLayout.createSequentialGroup()
                .addContainerGap()
                .addGap(18, 18, 18)
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox4)
                .addContainerGap(42, Short.MAX_VALUE))
        );


        ////////////////////////////////////////////////////////////////////////
        // Finalizar o layout

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).
                addGroup(layout.createSequentialGroup().
                addContainerGap()
                    .addComponent(controlePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(labirintoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, fator_de_escala*270, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labirintoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, fator_de_escala*220, Short.MAX_VALUE)
                    .addComponent(controlePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
        );

        // Montar

        pack();

        jCheckBox2.setSelected(true);
        jCheckBox3.setSelected(true);
        jCheckBox4.setSelected(true);
        gerarCaminho.setEnabled(false);
        expandir.setEnabled(false);
        origemdestino.setEnabled(false);
        grafo.setEnabled(false);
        Exibir.setVisible(false);
    }

    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    // Eventos do Mouse
    // Para o Labirinto
    private void campoMouseReleased(java.awt.event.MouseEvent evt)
    {
        if (action)
        {
            int rotacionar = JOptionPane.showConfirmDialog(this, "Mudar Orientação do obstaculo?");
            // Seleçao do botao de resposta: Yes, No, Cancel
            if (rotacionar == 0) {
                int angulo = Integer.parseInt(JOptionPane.showInputDialog(this, "Informe o ângulo de rotação: "));
                labirintoPanel.addObstaculos(evt.getX(), evt.getY(), controle2, true, angulo);
            } else {
                labirintoPanel.addObstaculos(evt.getX(), evt.getY(), controle2, true, 0);
            }
        } else if (inserirPontos) // Inserir Origem e Destino do Agente
        {
            labirintoPanel.setPontos(true);
            //System.out.println("Pontos: " + evt.getX() + "  " + evt.getY());
            if (n_pontos == 0) {
                labirintoPanel.setPtsOrigem(evt.getX(), evt.getY());
            } else {
                labirintoPanel.setPtsDestino(evt.getX(), evt.getY());
            }
            n_pontos++;
            if (n_pontos == 2) {
                n_pontos = 0;
                inserirPontos = false;
                gerarCaminho.setEnabled(true);
                caminhoTemp = true;
            }
        }
    }

    // Para o ToggleButton
    private void actionInserirFeito(java.awt.event.ActionEvent evt)
    {
        action = !action;
        controle++;
        if (action) {
            tamanho1.setBackground(azul);
            tamanho2.setBackground(Color.WHITE);
            tamanho3.setBackground(Color.WHITE);
            labirintoPanel.desenhaGridObstaculos1();
            inserir.setText("Finalizar");
        } else if (controle > 1) {
            labirintoPanel.grid = 0;
            inserir.setText("------");
            obstaculosPanel.setVisible(action);
            expandirTemp = true;
            expandir.setEnabled(true);
        }
    }


    // Botao para reiniciar
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt)
    {
        labirintoPanel.setStart(false);
        labirintoPanel.setExpandir(false);
        labirintoPanel.limparCampo();
        obstaculosPanel.setVisible(true);
        Exibir.setVisible(false);

        tamanho1.setBackground(Color.lightGray);
        tamanho2.setBackground(Color.lightGray);
        tamanho3.setBackground(Color.lightGray);
        inserir.setText("Inserir!");

        controle = 0;
        controle2 = 0;
        origemdestino.setEnabled(false);
        inserirPontos = false;
        gerarCaminho.setEnabled(false);
        expandir.setEnabled(false);
        labirintoPanel.setPontos(false);
        labirintoPanel.setPtsOrigem(-10, -10);
        labirintoPanel.setPtsDestino(-10, -10);
        action = false;
    }

    // Botoes para seleçao do tamanho do quadrado
    // Primeiro
    private void tamanho1ActionPerformed(java.awt.event.ActionEvent evt) {
        if (action) {
            controle2 = 0;
            tamanho1.setBackground(azul);
            tamanho2.setBackground(Color.WHITE);
            tamanho3.setBackground(Color.WHITE);
            labirintoPanel.desenhaGridObstaculos1();
        }
    }
    // Segundo
    private void tamanho2ActionPerformed(java.awt.event.ActionEvent evt) {
        if (action) {
            controle2 = 1;
            tamanho2.setBackground(azul);
            tamanho1.setBackground(Color.WHITE);
            tamanho3.setBackground(Color.WHITE);
            labirintoPanel.desenhaGridObstaculos2();
        }
    }
    // Terceiro
    private void tamanho3ActionPerformed(java.awt.event.ActionEvent evt) {
        if (action) {
            controle2 = 2;
            tamanho3.setBackground(azul);
            tamanho2.setBackground(Color.WHITE);
            tamanho1.setBackground(Color.WHITE);
            labirintoPanel.desenhaGridObstaculos3();
        }
    }


    // Botao Expandir
    private void expandirMouseClicked(java.awt.event.MouseEvent evt) {
        if(expandirTemp == true)
        {
            labirintoPanel.setExpandir(true);
            expandirTemp = false;
            expandir.setEnabled(false);
            origemdestino.setEnabled(true);
            odTemp = true;
        }
    }

    // Botao de Origem e Destino
    private void gerarMouseClicked(java.awt.event.MouseEvent evt) {
        if(odTemp)
        {
            inserirPontos = true;
            origemdestino.setEnabled(false);
            odTemp = false;
        }
    }

    // Botao pra Gerar Caminho
    private void gerarCaminhoMouseClicked(java.awt.event.MouseEvent evt)
    {
        if(caminhoTemp)
        {
            boolean espacoI, espacoF;

            // Mapeamento
            // Criar a arvore a partir da raiz que corresponde ao mapa inteiro
            Arvore mapa = new Arvore(labirintoPanel);

            // Divide o mapa em quatro celulas.
            // Caso as Celulas possuam obstaculos internamente, sao classificadas como mista ou ocupada.
            // Mista -> Divide a celula
            mapa.verificar();

            //Gerar o Grafo
            Caminho caminho = new Caminho(labirintoPanel, mapa.lista);
            caminho.identificarVizinhos();  // Construir o grafo a partir dessa analise

            //Definir Inicio e Fim
            espacoI = caminho.identificarInicio(labirintoPanel.getPtsOrigem()[0], labirintoPanel.getPtsOrigem()[1]);
            espacoF = caminho.identificarFinal(labirintoPanel.getPtsDestino()[0], labirintoPanel.getPtsDestino()[1]);

            if (espacoI == false) {
                JOptionPane.showMessageDialog(this, "Ponto de Inicio alocado em um espaço impróprio.");
            }
            if (espacoF == false) {
                JOptionPane.showMessageDialog(this, "Ponto de Destino alocado em um espaço impróprio.");
            }

            // Gerar Melhor Caminho
            caminho.melhorCaminho();

            grafo.setEnabled(false);
            Exibir.setVisible(true);
            gerarCaminho.setEnabled(false);
            caminhoTemp = false;
        }
    }

    private void percorrerMouseClicked(MouseEvent evt) {
        
    }

    public boolean getAction() {
        return action;
    }

    public int controleAcao() {
        return controle2;
    }

    private void jCheckBox1MouseClicked(java.awt.event.MouseEvent evt) {
        if(labirintoPanel.tempGrafo == 1)
            labirintoPanel.tempGrafo = 0;
        else
            labirintoPanel.tempGrafo = 1;
    }

    private void jCheckBox2MouseClicked(java.awt.event.MouseEvent evt) {
        if(labirintoPanel.tempCaminho == 1)
            labirintoPanel.tempCaminho = 0;
        else
            labirintoPanel.tempCaminho = 1;
    }

    private void jCheckBox3MouseClicked(java.awt.event.MouseEvent evt) {
        
        if(labirintoPanel.tempObstaculo == 1)
            labirintoPanel.tempObstaculo = 0;
        else
            labirintoPanel.tempObstaculo = 1;
    }

    private void jCheckBox4MouseClicked(java.awt.event.MouseEvent evt) {

        if(labirintoPanel.tempGrid == 1)
            labirintoPanel.tempGrid = 0;
        else
            labirintoPanel.tempGrid = 1;
    }

}
